import { parse } from 'url';
import { RechargeDetailItem, DetailItem, TableListParams } from './data';

function getRechargeDetail(
  req: { url: any },
  res: {
    json: (
      arg0: { code: number, body: RechargeDetailItem },
    ) => void;
  },
  u: any,
) {
  let new_url = u;
  if (!new_url || Object.prototype.toString.call(new_url) !== '[object String]') {
    new_url = req.url;
  }

  const dataSource: DetailItem[] = [];

  [...new Array(8)].map((item, index) => (
    dataSource.push({
      id: index + 1,
      total_amount: 0,
      sms_amount: 0,
      plat_service_amount: 0,
      stat_date: '2019-06-25 00:00:00',
      stat_unit: 'day',
    })
  ));

  const source = {
    stat_list: dataSource,
    diff_day_num: 10,
    storage_type: {
      0: '暂存区',
      1: '柜体',
      2: '货架',
      3: '地堆',
      4: '驿站',
      5: '新货架',
    },
    x_data: '06-21,06-22,06-23,06-24,06-25,06-26,06-27,06-28,06-29,06-30,06-31,07-01,07-02,07-03,',
    y_display_report_names: [
      {
        db_column: 'total_amount',
        name: '消费总金额',
        visible: 'true',
        is_money: 'true',
      },
      {
        db_column: 'sms_amount',
        name: '短信费',
        visible: 'true',
        is_money: 'true',
      },
      {
        db_column: 'plat_service_amount',
        name: '平台服务费',
        visible: 'true',
        is_money: 'true',
      },
    ],
    y_all_list: {
      total_amount: {
        y_list: [...new Array(14)].map(item => Math.ceil(Math.random() * 1000)),
        y_str: '0,0,0,0,0,0,0,0',
      },
      sms_amount: {
        y_list: [...new Array(14)].map(item => Math.ceil(Math.random() * 1000)),
        y_str: '0,0,0,0,0,0,0,0',
      },
      plat_service_amount: {
        y_list: [...new Array(14)].map(item => Math.ceil(Math.random() * 1000)),
        y_str: '0,0,0,0,0,0,0,0',
      },
    },
  };

  const result = {
    code: 0,
    body: source,
  };

  return res.json(result);
}

export default {
  'GET /consume/stat/index': getRechargeDetail,
};
